<%--
  Created by IntelliJ IDEA.
  User: zhitb
  Date: 2021/10/09
  Time: 19:12
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<html>
<head>
    <title>Title</title>
    <style>
        td{
            text-align: center;
        }
    </style>

</head>
<body>
<form action="/SelectStuListServlet" method="post">
    姓名:<input type="text" name="stuName"  id="stuName" value="${stuName}">
    学号:<input type="text" name="stuNo"  id="stuNo" value="${stuNo}">
    <input type="submit"  value="查询">
</form>
<a href="/myschool/addStu.jsp">添加</a>
<input id="hd" type="hidden" name="n" value="${n}">
  <table border="1" cellspacing="0" cellpadding="0">
      <tr style="background-color: aqua">
          <th>学号</th>
          <th>姓名</th>
          <th>性别</th>
          <th>所属班级</th>
          <th>出生日期</th>
          <th>操作</th>
      </tr>
      <c:forEach var="student" items="${stuByNameAll}" varStatus="status">
          <tr
                  <c:if test="${status.count%2==0}">style="background-color: aqua"</c:if>
          >
              <td>${student.studentNo}</td>
              <td>${student.studentName}</td>
              <td>
                  <c:if test="${student.sex==0}">女</c:if>
                  <c:if test="${student.sex==1}">男</c:if>
              </td>
              <td>${student.grade.gradeName}</td>
              <td>${student.bornDate}</td>
              <td>
                  <%-- 先跳转到根据stuNo查询的servlet，然后转发到updateStu.jsp--%>
                  <a href="/SelectStuListServlet?stuNo=${student.studentNo}&action=update">修改</a>
                  <%-- 跳转至deleteStuByNoServlet，然后转发到stuList.jsp--%>
                  <a href="/DeleteStuByNoServlet?stuNo=${student.studentNo}">删除</a>
              </td>
          </tr>
      </c:forEach>
  </table>
<div>
    当前<span id="currentPage">${currentPage}</span>共<span id="totalPage">${totalPage}</span>>&ensp;&ensp;
    <a href="#" id="firstPage">首页</a>&ensp;&ensp;
    <a href="#" id="prevPage">上一页</a>&ensp;&ensp;
    <a href="#" id="nextPage">下一页</a>&ensp;&ensp;
    <a href="#" id="lastPage">尾页</a>&ensp;&ensp;
    到<input type="text" style="width: 30px" id="pageNum" value=""/>页<a href="#" id="goPage">Go</a>>
</div>
<script src="../js/jquery-3.6.0.min.js"></script>

<script>
    //js后端获取参数
    var n = document.getElementById("hd").value;
    if (n!=null&&n!=""){
        if (n>0){
            alert("更新成功");
        }else {
            alert("更新失败");
        }
    }
    $(function (){
        var currentPage=parseInt($("#currentPage").text());
        var totalPage=parseInt($("#totalPage").text());
        var stuName=$("#stuName").val();
        var stuNo=$("#stuNo").val();

        $("#firstPage").click(function (){
            currentPage=1;
            location.href="/SelectStuListServlet?currentPage="+currentPage+"&stuNo="+stuNo+"&stuName="+stuName;
        })
        $("#prevPage").click(function (){
            if (currentPage<=1){
                alert("前面没了");
                return;
            }
            currentPage=currentPage-1;
            location.href="/SelectStuListServlet?currentPage="+currentPage+"&stuNo="+stuNo+"&stuName="+stuName;
        })
        $("#nextPage").click(function (){
            if (currentPage>=totalPage){
                alert("后面没了");
                return;
            }
            currentPage=currentPage+1;
            location.href="/SelectStuListServlet?currentPage="+currentPage+"&stuNo="+stuNo+"&stuName="+stuName;
        })
        $("#lastPage").click(function (){
            currentPage=totalPage;
            location.href="/SelectStuListServlet?currentPage="+currentPage+"&stuNo="+stuNo+"&stuName="+stuName;
        })

    })
</script>

</body>
</html>
